import Vue from 'vue'
import Vuex from 'vuex'
import {login } from '@/api/user'
import { setToken,getToken} from '@/utils/storage'
Vue.use(Vuex)
export default new Vuex.Store({
  state:{
    token: getToken() || ''
  },
  mutation:{
    loginl(state,payload){
      state.token = payload
      setToken(payload)
   } 
  },
 actions:{
    async loginForm(context,val){
    const {data:res} =await login(val)
      console.log(res)
      if(res.errmsg === "登录成功"){
        context.commit('loginl',res.data.token)
      }else{
        // Toast(res.errmsg)
        console.log(1)
      }
    }
  }
})